import gsap from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
export function useGsapBackgroundAnimation(selectors: string, parallaxFactor: number = 0.5) {
	gsap.registerPlugin(ScrollTrigger);
	const sections = document.querySelectorAll(selectors);
	sections.forEach(selector => {
		const scrollDistance = (selector.clientHeight * parallaxFactor).toFixed(0);
		gsap.fromTo(
			selector,
			{
				backgroundPositionY: `-${scrollDistance}px`
			},
			{
				backgroundPositionY: `${scrollDistance}px`,
				ease: "none",
				scrollTrigger: {
					trigger: selector,
					scrub: 0.4 //把动画速度和滚动条速度同步
				}
			}
		);
	});
}
